package util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {

	public static final String MYSQL_DB_DATE_PATTERN = "yyyy-MM-dd";
	public static final String MYSQL_DB_TIME_PATTERN = "H:m:s";

	public static final String DESIRED_DATE_PATTERN = "ddMMyyyy";
	public static final String DESIRED_TIME_PATTERN = "Hm";

	public static String formatDate(String date) {
		return formatDate(MYSQL_DB_DATE_PATTERN, DESIRED_DATE_PATTERN, date);
	}

	public static String formatTime(String time) {
		return formatDate(MYSQL_DB_TIME_PATTERN, DESIRED_TIME_PATTERN, time);
	}

	private static String formatDate(String originalPattern,
			String desiredPattern, String date) {
		try {
			SimpleDateFormat originalFormat = new SimpleDateFormat(
					originalPattern);
			SimpleDateFormat desiredFormat = new SimpleDateFormat(
					desiredPattern);
			Date parsedDate = originalFormat.parse(date);
			return desiredFormat.format(parsedDate);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}

}
